package Biz;


import javax.jms.Message;
import javax.jms.MessageListener;
import javax.ejb.*;
import javax.annotation.*;
import javax.jms.*;

import Message.PcrResultMessage;
/**
 * Message-Driven Bean implementation class for: PTPMessageBean
 */
@MessageDriven(activationConfig =  {
        @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Topic"),
        @ActivationConfigProperty(propertyName = "destination", propertyValue = "topic/test"),
        @ActivationConfigProperty(propertyName = "subscriptionDurability", propertyValue = "Durable"),
        @ActivationConfigProperty(propertyName = "clientID", propertyValue = "consumer")
        
    })


public class ResultMessageBean implements MessageListener {
    @Resource
    private MessageDrivenContext mdc;
    
    @EJB
    Biz.updateTubeBean updateTubeBean;    
    public ResultMessageBean() {
    }

    public void onMessage(Message inMessage) {
        TextMessage msg = null;
        try {
            if (inMessage instanceof TextMessage) {
                msg = (TextMessage) inMessage;
                
                PcrResultMessage message=PcrResultMessage.deserializeToObject(msg.getText());
                updateTubeBean.update(message.tube_ID, message.result, message.resultTime);
            }
        } catch (Throwable te) {
            te.printStackTrace();
        }

    }
    
}
